<template>
	<view class="page">
		<CustomNav :isBack="true" color="#fff" :topBgColor="topBgColor" :title="title"></CustomNav>
		<image src="https://jinta-gas-charge-1306862033.cos.ap-chengdu.myqcloud.com/uniapp/home/banner.png"
			class="bg-img" mode="widthFix"></image>
		<view class="info-block">
			<template v-if="list.length>0">
				<view class="info-list" v-for="item in list" :key="item.id" @click="navigate('/page_pack/notice/notice?id='
					+item.id)">
					<view class="name">{{item.title}}</view>
					<view class="time-item">
						<view class="time">{{item.createTimeStr}}</view>
						<view class="iconfont icon-yanjing"><text class="text">{{item.viewsNumber||0}}</text></view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'
	import {
		getPublicListApi
	} from '@/api/information.js'
	export default {
		components: {},
		data() {
			return {
				topBgColor: 'rgba(0,0,0,0)',
				// list: [{
				// 		id: 1,
				// 		title: '金塔县市场监督管理局多部门联动加强餐饮企业燃气安全监督检查',
				// 		creatTime: '2024-07-18',
				// 		number: 214
				// 	},
				// 	{
				// 		id: 2,
				// 		title: '金塔县民政局开展养老机构燃气安全检查',
				// 		creatTime: '2023-06-30',
				// 		number: 331
				// 	}, {
				// 		id: 3,
				// 		title: '金塔县开展居民燃气安全大排查大治理大提升行动',
				// 		creatTime: '2023-05-08',
				// 		number: 204
				// 	}
				// ]
				conf: {
					page: 1,
					limit: 10,
					name: ''
				},
				more: true,
				list: [],
				type: 1,
				title: ''
			}
		},
		methods: {
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getPublicListApi({
					page: this.conf.page,
					limit: this.conf.limit,
					type: this.type
				}).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;

					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				})
			}
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				this.getList();
			}
		},
		onLoad(e) {
			this.type = e.type
			if (e.type == 1) {
				this.title = '信息公告'
			} else {
				this.title = '停气通知'
			}
		},
		onShow() {
			this.getList(true)
		}
	}
</script>

<style lang="scss">
	.page {
		overflow: hidden;
		min-height: 100vh;
		background-color: #F4F8FF;

		.bg-img {
			width: 100%;
			height: 100%;
		}

		.info-block {
			width: calc(100% - 60rpx);
			margin: 30rpx auto;
			margin-top: -90rpx;

			.info-list {
				background: #FFFFFF;
				border-radius: 20rpx;
				margin-bottom: 30rpx;
				padding: 30rpx;

				.name {
					font-size: 30rpx;
					line-height: 54rpx;
				}

				.time-item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 20rpx;
					color: #767676;
					font-size: 26rpx;

					.iconfont {
						font-size: 30rpx;
						display: flex;
						align-items: center;

						.text {
							font-size: 26rpx;
							margin-left: 10rpx;
						}
					}
				}
			}
		}
	}
</style>